<template>
  <div>
    <mainFrame>
      <div slot='content'>
        <div style="margin-left: 150px;">
          <el-button type="primary" @click="back" icon="el-icon-back">返回</el-button>
        </div>
        <ttForm v-model="form"></ttForm>
      </div>
    </mainFrame>
  </div>
</template>
<script>
import mainFrame from '@/components/mainFrame'
import utils from '../ttJs/utils.js'
import ttForm from '@/tt_components/ttForm'
export default {
  components: {
    mainFrame,
    ttForm
  },
  data() {
    return {
      areaId: null,
      form: {
        id: null,
        url: '/yitai/admin/updateMachine',
        items: [
          { name: 'areaId', value: null },
          { name: 'location', value: '', label: '归属地', placeholder: '请输入归属地', type: 'input', disabled: true, style: 'width: 220px' },
          { name: 'areaNo', value: 0, label: '台区号', placeholder: '请输入台区号', type: 'input', disabled: true, style: 'width: 220px' },
          { name: 'machineNo', value: '', label: '换相器号', placeholder: '请输入换相器号', type: 'input', style: 'width: 220px' },
          { name: 'time', value: new Date(), label: '时间', placeholder: '请选择时间', type: 'datetime' },
          { name: 'track', value: '', list: [{ id: 1, title: '1' }, { id: 2, title: '2' }],  label: '支路', type: 'radio' },
          { name: 'activeStatus', value: 0, list: [{ id: 1, title: '是' }, { id: 0, title: '否' }], label: '激活状态', type: 'radio' },
          { name: 'installAddress', value: '', label: '安装地点', placeholder: '请输入安装地点', type: 'input', style: 'width: 500px' },
        ],
        items2: [
          { name: 'location', value: '', label: '归属地', placeholder: '请输入归属地', type: 'input' },
          { name: 'areaNo', value: 0, label: '台区号', placeholder: '请输入台区号', type: 'input' },
          { name: 'machineNo', value: '', label: '换相器号', placeholder: '请输入台区地点', type: 'input' },
          { name: 'time', value: new Date(), label: '时间', placeholder: '请选择时间', type: 'datetime' },
          { name: 'WORKL', value: '', label: 'WORKL', placeholder: '请输入WORKL', type: 'input' },
          { name: 'STAT', value: '', label: 'STAT', placeholder: '请输入STAT', type: 'input' },
          { name: 'I', value: '', label: 'I', placeholder: '请输入I', type: 'input' },
          { name: 'Ub', value: '', label: 'Ua', placeholder: '请输入Ua', type: 'input' },
          { name: 'Ua', value: '', label: 'Ub', placeholder: '请输入Ub', type: 'input' },
          { name: 'Uc', value: '', label: 'Uc', placeholder: '请输入Uc', type: 'input' },
          { name: 'PF', value: '', label: 'PF', placeholder: '请输入PF', type: 'input' },
          { name: 'track', value: '', list: [{ id: 1, title: '1' }, { id: 2, title: '2' }],  label: '支路', type: 'radio' },
          { name: 'activeStatus', value: 0, list: [{ id: 1, title: '是' }, { id: 0, title: '否' }], label: '激活状态', type: 'radio' },
          { name: 'installAddress', value: '', label: '安装地点', placeholder: '请输入安装地点', type: 'input' },
        ]
      },
    };
  },
  mounted: function() {
    this.getInfo()
  },

  methods: {
    getInfo() {
      var self = this;
      if (utils.validateData(self.$route.query.areaId)) {
        self.getAreaInfo();
      }
      if (utils.validateData(self.$route.query.id)) {
        var id = self.$route.query.id;
        self.form.id = id;
        var url = '/yitai/admin/machineInfo';
        var areaId = self.$route.query.areaId
        //this.form.items[0].value = areaId
        this.areaId = areaId
        var params = { id: id }
        var success = function(response) {
          var info = response.info;
          var items = self.form.items
          for (var index in items) {
            for (var key in info) {
              if (items[index].name == key) {
                items[index].value = info[key]
              }
            }
          }
          self.form.items[3].disabled = true;
        }
        var fail = function() {
          utils.fail('加载失败')
        }
        var complete = function() {}
        utils.requestLoading(url, params, success, fail, complete)
      }
    },
    getAreaInfo() {
      var self = this;
      var url = '/yitai/admin/areaInfo';
      var params = { id: self.$route.query.areaId }
      var success = function(response) {
        self.form.items[0].value = response.info.id;
        self.form.items[1].value = response.info.location;
        self.form.items[2].value = response.info.areaNo;
      }
      var fail = function() {
        utils.fail('加载台区信息失败')
      }
      var complete = function() {}
      utils.requestLoading(url, params, success, fail, complete)
    },
    back() {
      window.history.back();
    }
  },
}

</script>
<style scoped rel="stylesheet/scss" lang="scss">
.page {
  position: relative;
  overflow: hidden;
  padding: 20px;
}

.el-input {
  width: 350px;
}

</style>
